package com.example.shixunandjavagotoyangchen.BoosYang.Day002;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandContion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandPresenter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersContion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersPresenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay002_1103 extends BasterFragment implements OnRefreshLoadMoreListener, SneakersContion.vier {

    public static SmartRefreshLayout SneakersSmartRefreshLayout;
    private RecyclerView SneakersRecyclerView;
    public SneakersAdpter adpter;
    public SneakersPresenter presenter;
    public boolean isning = true;
    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day002_1103;
    }

    @Override
    public void initView() {

        SneakersSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Sneakers_SmartRefreshLayout);
        SneakersRecyclerView = (RecyclerView) findViewById(R.id.Sneakers_RecyclerView);
        SneakersRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        SneakersSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        presenter = new SneakersPresenter(this,new SneakersModel());
        presenter.sneakering("Home_zidingyi.php");

    }

    @Override
    public void initDate() {

    }

    // TODO: Rename parameter arguments, choose names that match

    @Override
    public void getvier(List<SneakersBean.ShujuBean> dataBeans) {
        SneakersSmartRefreshLayout.finishLoadMore();
        SneakersSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new SneakersAdpter(dataBeans);
            SneakersRecyclerView.setAdapter(adpter);
        }else {
            if (isning){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        isning =false;
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (isning){
            Log.i("aaa","la1");
        }
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();

    }
}
